<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@include file="../WEB-INF/jspf/controlesessao.jspf"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Alterar Modulos</title>
        <script type="text/javascript" src="../js/jquery.js" ></script>
        <script type="text/javascript" src="../js/jquery.validate.js"></script>
        <script type="text/javascript" src="../js/forms.js"></script>
        <script type="text/javascript" src="../js/jquery-ui-1.8.2.custom.min.js" ></script>
        <link rel="stylesheet" href="../css/ui-lightness/jquery-ui-1.8.2.custom.css">
    <link rel="stylesheet" href="../css/forms.css"></head>
    <script>

        $(document).ready(function(){
            $("#form").validate({
                rules: {
                    id_curso: {required: true,digits: true
                    }
                    ,desc_modulo: {}
                },
                submitHandler: function(form) {
                    salvar(form);
                }
            });
        });
    </script>


    <body>
       
        <form name="form" id="form" method="post" action="update.jsp" >
            <div id="formulario">
                <fieldset><legend>Dados</legend>
                    <sql:query var="query" dataSource="jdbc/dbo_MicrosoftSQLServer">
                        SELECT  Modulos.*,
                        cursos.nome_curso,
                        areas.desc_area
                        FROM Modulos
                        inner join cursos on modulos.id_curso=cursos.id_curso
                        inner join areas on areas.id_area=cursos.id_area
                        where id_modulo=?
                        <sql:param value="${param.chave}"/>
                    </sql:query>


                    <c:forEach var="row" items="${query.rows}">
                        <p><label class="lbInput">Área </label>${row.desc_area}
                        </p>
                        <p><label class="lbInput">Curso </label>${row.nome_curso}
                        </p>
                        <input type="hidden" name="id_modulo" size="10" maxlength="10" class="required" value="${row.id_modulo}">
                        <input type="hidden" name="id_curso" size="10" maxlength="10" class="required" value="${row.id_curso}">
                        <p><label class="lbInput">Módulo<em>*</em></label>
                            <input type="text" name="desc_modulo" size="60" maxlength="100" class="required" value="${row.desc_modulo}">
                        </p>
                        <p>
                        <div id="componentes">
                            <sql:query var="queryComponentes" dataSource="jdbc/dbo_MicrosoftSQLServer">
                                SELECT  Componentes.*, id_modulo , cursos.id_curso
                                FROM grades
                                right join Componentes on id_modulo=? and grades.id_componente=Componentes.id_componente
                                right join Cursos on grades.id_curso=cursos.id_curso
                                where cursos.id_curso=?
                                <sql:param value="${row.id_modulo}"/>
                                <sql:param value="${row.id_curso}"/>
                            </sql:query>

                            <c:forEach var="componente" items="${queryComponentes.rows}">
                                <input type="checkbox" name="id_componente" value="${componente.id_componente}" ${componente.id_modulo==null?'':'checked'}>
					<label>${componente.desc_componente}</label><br>
                            </c:forEach>
                        </div>
                    </c:forEach><p>
                        <input class="submit" type="button" value="Listar" onclick="listar('fm_lista_Modulos.jsp')">
                    </p>
                    <div id="ajax_dados" style="display:block">
                    </div>
                    <div id="msg" style="display:none"></div>
                </fieldset>
            </div>
        <input type="hidden" id="token" name="token" value="${sessionScope.token}" /> </form>
    </body>
</html>
